import { Toast } from 'vant'
import $api from '../index'
// 获取注册验证码
export const Sms = async (res: string) => {
  const { data } = await $api.post('/common/getCode', { phone: res, type: 'reg' })
  console.log(data)
  return data
}
// 注册
interface RegParams {
  phone?: string
  code?: string,
  lxName?: string,
  pwd?: string,
}
export const Reg = async (res: RegParams) => {
  const { data } = await $api.post('/bus/company/reg', res)
  return data
}
// 账号密码登录
interface LoginParams {
  phone: string
  pwd: string
}
export const Login = async (res: LoginParams) => {
  const { data } = await $api.post('/bus/loginByPhone', res)
  if (data.success) {
    const json = JSON.stringify(data)
    localStorage.setItem('token', json)
  } else {
    Toast(data.info)
  }
  return data
}
